
# 1、打开文件
# 2、操作文件
# 3、关闭文件

# fp = open('E:\\rw.txt', mode='r', encoding='UTF-8')
    
# 读取所有内容
# result = fp.read()

# 读取前几个字符
# result = fp.read(3)

# 读取一行
# result = fp.readline()
# result = fp.readlines()

# print(result)

# fp = open('E:\\rw.txt', mode='w', encoding='UTF-8')

# fp = open('E:\\rw.txt', mode='a', encoding='UTF-8')
# fp.write('Hello world\n')
# fp.write('中国\n')
# fp.writelines('娃哈哈\n')
# fp.writelines('beautiful\n')
# fp.close()



with open('E:\\rw.txt', mode='a', encoding='UTF-8') as fp:

    fp.write('自动关闭文件\n')
    fp.write('中国\n')
    fp.writelines('娃哈哈\n')
    fp.writelines('success\n')